package com.代理模式;

public class jingtai {
    public static void main(String[] args) {
        Speaker zhangSan = new ZhangSan();
        Lawyer lawyer = new Lawyer(zhangSan);
        lawyer.speak();
    }

}

interface Speaker{ //可以有很多实现类（张三，李四，王五等），不可能每次都把具体的代理类写好，而是需要在运行的过程中动态创建代理对象
    public void speak();
}

class ZhangSan implements Speaker{

    @Override
    public void speak() {
        System.out.println("我老婆打我!");
    }
}

class Lawyer implements Speaker{

    private Speaker speaker;

    public Lawyer(Speaker speaker){
        this.speaker = speaker;
    }

    @Override
    public void speak() {
        System.out.println("引用法律条文！");
        speaker.speak();
        System.out.println("打人是不对的！");
    }
}
